@echo off
setlocal enabledelayedexpansion

set branch=%1
set clean=%2
set buildFunc=%3
set basePath=%4
set logFile="-"

if %basePath% == "" (
	set basePath=C:\mateurp_pipline\mateurp
)

set projectPath=%basePath%\mateurp

if "%branch%" == "" (
	echo branch must be set
    exit /b 1
)

if %buildFunc% == "" (
	set buildFunc=BuildArtAB
)

cd /d %basePath%

:: Update Code
echo Update Code Start
git checkout %branch%
git fetch origin || exit /b 1
git reset --hard "origin/%branch%" || exit /b 1
echo Update Code Finish

:: GenerateAll
echo GenerateAll Start
"C:\Program Files\Unity\Hub\Editor\2022.3.61f1c1\Editor\Unity.exe" -batchmode -nographics -quit -projectPath "%projectPath%" -executeMethod HybridCLR.Editor.BuildAssetsCommand.Prebuild -logFile %logFile% || exit /b 1
echo GenerateAll Finish

:: BuildAssets
echo BuildAssets Start

if "%clean%" == "true" (
	rd /s /q %projectPath%\HybridCLRBuildCache\ArtPackages
	rd /s /q %projectPath%\ArtPackages
)

"C:\Program Files\Unity\Hub\Editor\2022.3.61f1c1\Editor\Unity.exe" -batchmode -nographics -quit -projectPath "%projectPath%" -executeMethod HybridCLR.Editor.BuildAssetsCommand.%buildFunc% -logFile %logFile% || exit /b 1
echo BuildAssets Finish
endlocal